<template>
    <view class="page" :style="{'padding-top':navigationbarHeight+'px','min-height': 'calc(100vh - '+navigationbarHeight+'px)'}">
        <TopBar :showName='showName' :BackgroundColor.sync="BackgroundColor"  ></TopBar>
        <view class="page-top">
            <img mode="widthFix" src="http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/rank-top.png" />
            <view class="page-top-title">
                {{circle_name}}
            </view>
        </view>
        <view class="user-info">
            <view class="user-info-top">
                <view class="info-top-left">
                    <img :src="userInfo.photo_url" />
                </view>
                <view class="info-top-center">
                    <p>{{userInfo.user_name}}<img v-if="userInfo.user_grade" :src="'http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/LV'+userInfo.user_grade+'.png'"/></p>
                    <text>经验值{{userInfo.exp_num}}</text>
                </view>
                <view class="info-top-right" @click="skipLevel(circle_id,userInfo.user_grade)">
                    <img src="/static/img/exp-icon.png" />
                    <text>如何获取经验值</text>
                </view>
            </view>
            <view class="user-info-bottom">
                <div class="bar-wrapper">
                    <div class="bar-item" v-for="index in 15" :key="index">
                        <div :class="{'circle':true,circleActive:index<userInfo.user_grade}"></div>
                        <div class="first" style="left: -10rpx">LV{{index+1}}</div>
                        <div :class="{'bar':true,barActive:(index+1)<userInfo.user_grade}" v-if="index!=14"></div>
                    </div>
                </div>
            </view>
        </view>
        <view class="rank-list">
            <view class="rank-list-top">
                <view class="list-top-left">
                    月贡献榜 {{month_time.startTime}}-{{month_time.endTime}}
                </view>
                <view class="list-top-right">
                    榜单规则<img src="/static/img/right-white.png" />
                </view>
            </view>
            <view class="rank-list-bottom">
                <view class="rank-list-itme" v-for="(item,index) in rankList" :key="item.id">
                    <view class="list-item-left">
                        <view v-if="index==0"><img src="https://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/number-one.png"></view>
                        <view v-if="index==1"><img src="https://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/number-two.png"></view>
                        <view v-if="index==2"><img src="https://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/number-three.png"></view>
                        <view v-if="index>2">{{index+1}}</view>
                    </view>
                    <view class="list-item-right">
                        <view class="list-item-head-g" @click="skipPerson(item.user_id)">
                            <view class="item-head-portrait-b Number-one" v-if="index==0">
                                <img :src="item.photo_url" />
                            </view>
                            <view class="item-head-portrait-b Number-two" v-if="index==1">
                                <img :src="item.photo_url" />
                            </view>
                            <view class="item-head-portrait-b Number-three" v-if="index==2">
                                <img :src="item.photo_url" />
                            </view>
                            <view class="item-head-portrait-b Number-ordinary" v-if="index>2">
                                <img :src="item.photo_url" />
                            </view>
                            <view class="item-head-name">
                                <view class="name">
                                    <p>{{item.user_name}}</p>
                                    <img v-if="item.user_grade" :src="'http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/'+item.user_grade+'.png'"/>
                                </view>
                                <text>经验值{{item.exp_num}}</text>
                            </view>
                            <view class="item-follow" v-if="item.user_id != userInfo.user_id">
                                <img v-if="item.i_follow_it==0" @click.stop="followUser(item.user_id)" src="http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/rank-follow.png" />
<!--                                <button size="mini" v-if="item.i_follow_it==0" @click.stop="followUser(item.user_id)">+关注</button>-->
                                <button size="mini" v-if="item.i_follow_it==1&&item.it_follow_me==0" @click.stop="unFollowUser(item.user_id)">已关注</button>
                                <button size="mini" v-if="item.i_follow_it==1&&item.it_follow_me==1" @click.stop="unFollowUser(item.user_id)">已互关</button>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
    import TopBar from "@/pages/components/topBar/topBar";
    export default {
        name: "rankList",
        components: {TopBar},
        data(){
            return{
                navigationbarHeight: getApp().globalData.navStyle.navigationbarHeight,
                circle_id:'',
                userInfo: {},
                rankList: [],
                circle_name:'',
                month_time: {},
                // user_id:'',
                page:1,
                total: '',
                showName: 'white',
                BackgroundColor:false
            }
        },
        onLoad(query){
            console.log(query)
            this.circle_id = query.circle_id;
            this.circle_name = query.circle_name;
            // this.user_id = uni.getStorageSync('userId')
            this.circleUserLeaderBoard();
        },
        onShow(){
        },
        onPageScroll(e){
            // console.log(e)
            if (e.scrollTop > 0){
                this.BackgroundColor = true;
            }else {
                this.BackgroundColor = false;
            }

        },
        methods:{
            //获取哔哔榜列表
            async circleUserLeaderBoard(){
                let params = {
                    page: this.page,
                    limit: 10,
                    circle_id: this.circle_id,
                    user_token: uni.getStorageSync('userToken')
                }
                const res = await this.$api.circleUserLeaderBoard(params);
                if (res.data.level == 'success'){
                    this.rankList = res.data.data;
                    this.userInfo = res.data.user_exp;
                    this.total = res.data.page_info.total;
                    this.month_time = res.data.month_time;
                }else {
                    uni.showToast({
                        icon:'none',
                        title:res.data.message
                    })
                }
            },
            async unFollowUser(id){
                //取关
                let params={
                    user_token:uni.getStorageSync('userToken'),
                    user_id:id
                }
                let res=await this.$api.unFollowUser(params);

                if(res.data.level=='success'){
                    uni.showToast({
                        icon:'success',
                        title:res.data.message
                    })
                    this.circleUserLeaderBoard();
                }else {
                    uni.showToast({
                        icon:'none',
                        title:res.data.message
                    })
                }
            },
            async followUser(id){
                //关注
                let params={
                    user_token:uni.getStorageSync('userToken'),
                    user_id:id
                }
                let res=await this.$api.followUser(params)
                if(res.data.level=='success'){
                    uni.showToast({
                        icon:'success',
                        title:res.data.message
                    })
                    this.circleUserLeaderBoard();
                }else {
                    uni.showToast({
                        icon:'none',
                        title:res.data.message
                    })
                }
            },
            //跳转用户详情
            skipPerson(id){
                uni.navigateTo({
                    url: "/pages/person/customHomepage/customHomepage?userId="+id
                })
            },
            //跳转等级详情
            skipLevel(id,level){
                uni.navigateTo({
                    url: "/pages/circlebar/circlebarLevel/circlebarLevel?circle_id="+id+"&level="+level
                })
            }
        }
    }
</script>

<style scoped lang="scss">
    @import '~@/static/scss/mixin.scss';
    .page{
        padding: 30rpx;
        width: calc(100vw - 60rpx);
        background-image: url("http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/rank-bgk.png");
        background-repeat: repeat-y;
        background-position: center;
        background-size: cover;
    }
    .page-top{
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        position: relative;
        img{
            width: 100%;
        }
        .page-top-title{
            position: absolute;
            background: #FA3A00;
            border-radius: 27rpx;
            top: 20rpx;
            left: 30rpx;
            width: 188rpx;
            height: 54rpx;
            padding: 0 20rpx;
            text-align: center;
            line-height: 54rpx;
            font-size: 28rpx;
            color: #FFFFFF;
            font-weight: bold;
            overflow: hidden;
            text-overflow: ellipsis;
            word-wrap: break-word;
            display: -webkit-box;
            -webkit-line-clamp:1;
            -webkit-box-orient: vertical;
        }
    }
    .user-info{
        background: #ffffff;
        padding: 30rpx;
        border-radius: 20rpx;
        margin-bottom: 30rpx;
        z-index: 20;
        .user-info-top{
            display: flex;
            flex-direction: row;
            justify-content: left;
            align-items: center;
            .info-top-left{
                width: 15vw;
                height: 15vw;
                border-radius: 360rpx;
                overflow: hidden;
            }
            .info-top-center{
                width: 40vw;
                display: flex;
                flex-direction: column;
                justify-content: left;
                padding: 3vw;
                p{
                    font-size: 30rpx;
                    font-weight: bolder;
                    margin-bottom: 14rpx;
                    max-width: 100%;
                    line-height: 40rpx;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    word-wrap: break-word;
                    display: flex;
                    img{
                        margin-left: 6rpx;
                        height: 40rpx;
                        width: 68rpx;
                    }
                }
                text{
                    font-size: 22rpx;
                    color: #8B8D93;
                }
            }
            .info-top-right{
                width: calc(39vw - 120rpx);
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                img{
                    width: 50rpx;
                    height: 50rpx;
                    margin: 10rpx;
                }
                text{
                    font-size: 22rpx;
                    color: #8B8D93;
                }
            }
        }
        .user-info-bottom{
            .bar-wrapper{
                margin:40rpx 20rpx;
                @include flex(left,center);
                overflow: hidden;
                height: 90rpx;
                overflow-x: scroll;
                overflow-y: hidden;
                .bar-item{
                    position: relative;
                    @include flex();
                    .circle{
                        border-radius: 50%;
                        background:#fff ;
                        height: 20rpx;
                        width: 20rpx;
                        border:6rpx solid #E5E6E7;
                    }
                    .circleActive{
                        background:#FFE226 ;
                        border:6rpx solid rgba(41,41,41,1);


                    }
                    .bar{
                        width: 40rpx;
                        height: 10rpx;
                        background:#E5E6E7 ;
                    }
                    .barActive{
                        background:rgba(41,41,41,1) ;

                    }
                    .first{
                        position: absolute;
                        bottom: -30rpx;
                        color:#8B8D93;
                        font-size: 20rpx;
                    }
                }
            }
        }
    }
    .rank-list{
        width: 100%;
        border-radius: 16rpx;
        overflow: hidden;
        .rank-list-top{
            width: 100%;
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            background: #FF521D;
            color: #ffffff;
            .list-top-left{
                padding: 30rpx;
                width: 60%;
                font-size: 28rpx;
            }
            .list-top-right{
                padding: 30rpx;
                width: 40%;
                display: flex;
                flex-direction: row;
                justify-content: flex-end;
                font-size: 26rpx;
                align-items: center;
                img{
                    width: 26rpx;
                    height: 26rpx;
                    vertical-align: middle;
                }
            }
        }
        .rank-list-bottom{
            background: #ffffff;
            /*padding: 20rpx;*/
        }
    }
    .rank-list-itme{
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        border-bottom: 2rpx solid #E6E6E6;
        padding: 10rpx 30rpx 10rpx 20rpx;
        .list-item-left{
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            view{
                width: 60rpx;
                height: 60rpx;
                font-size: 32rpx;
                line-height: 60rpx;
                text-align: center;
                font-weight: bold;
                img{
                    width: 60rpx;
                    height: 60rpx;
                }
            }
        }
        .list-item-right{
            display: inline-block;
            width: 90%;
            background: #ffffff;
            .list-item-head-g{
                height: auto;
            }
        }
    }
    .Number-one{
        background-image: url("http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/rank-number-one.png");
        background-repeat: no-repeat;
        background-size: cover;
        background-position: center;
    }
    .Number-two{
        background-image: url("http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/rank-number-two.png");
        background-repeat: no-repeat;
        background-size: cover;
        background-position: center;
    }
    .Number-three{
        background-image: url("http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/rank-number-three.png");
        background-repeat: no-repeat;
        background-size: cover;
        background-position: center;
    }
    .Number-ordinary{
        background-image: url("http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/bbMachine/rank-number-ordinary.png");
        background-repeat: no-repeat;
        background-size: cover;
        background-position: center;
    }
    .item-head-portrait-b{
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 20rpx;
        height: 80rpx;
        width: 80rpx;
        margin: 0 10rpx;
        img{
            border-radius: 360rpx;
        }
    }
    .item-head-name{
        .name{
            margin-bottom: 10rpx;
            p{
                line-height: 40rpx;
                height: 40rpx;
                margin-bottom: 0;
            }
        }
        text{
            font-size: 22rpx;
            height: 22rpx;
            line-height: 22rpx;
        }
    }
    .item-follow{
        margin-left:auto;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        /*width: 100rpx;*/
        img{
            width: 88rpx;
            height: 44rpx;
            /*border: 1rpx dotted #000000;*/
            /*padding: 1rpx;*/
        }
        button{
            width: 88rpx;
            height: 44rpx;
            font-size: 20rpx;
            background: #f7f7f7;
            padding: 0;
            text-align: center;
            margin-top: 0;
            margin-right: 0;
            border-radius: 20rpx;
        }
    }
</style>